- Senior Software Engineer
- CDI co-spec lead, Java EE 8 EG
- Red Hat, Inc.
- @antoine_sd
- www.next-presso.com
- github.com/antoinesd
| Slides available at rafabene.github.io/deltaspike-cdi-toolbox/ |
| OCP (Open Closed Principle) in CDI |
| To integrate 3rd party libraries, frameworks or legacy components |
| To change existing configuration or behavior |
| To extend CDI and Java EE |
| Thanks to them, Java EE can evolve between major releases |
| Implement javax.enterprise.inject.spi.Extension |
| Register the Extension |
| Observe SPI events at boot time related to the bean manager lifecycle |
Service provider of the service javax.enterprise.inject.spi.Extension declared in META-INF/services |
| Just put the fully qualified name of your extension class in this file |
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;
public class CdiExtension implements Extension {
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) {
}
//...
void afterDeploymentValidation(@Observes AfterDeploymentValidation adv) {
}
} @Inject @Property("key1")
private String property1;
@Inject @Property("key2")
private String property2;| It can be achieved by @Produces but it could lead to: Unsatisfied dependencies for type String with qualifiers @Property… |
@Produces
@Property("key1")
public String propriedade1Producer()
{
return propertiesFile.getProperty("key1");
}| One of the most powerful feature of the CDI specification |
| Not really popularized, partly due to: |